package com.cnzhy.binding;

import com.cnzhy.config.MapperStatement;
import com.cnzhy.session.MyConfiguration;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author 赵 岩
 */
public class MyMapperRegistry {

    private static ConcurrentMap<String, MapperStatement> concurrentHashMap = new ConcurrentHashMap<>();

    public static ConcurrentMap<String, MapperStatement> getConcurrentHashmap() {
        return concurrentHashMap;
    }

    public static void setConcurrentHashmap(String key, MapperStatement mapperBean) {
        concurrentHashMap.put(key, mapperBean);
    }

    public static MapperStatement getMapperBean(String key) throws Exception {
        if (concurrentHashMap.get(key) != null) {
            return concurrentHashMap.get(key);
        }
        synchronized (MyMapperRegistry.class) {
            new MyConfiguration().registryMappers("mapper");
            if (concurrentHashMap != null) {
                return concurrentHashMap.get(key);
            }
        }
        return null;
    }
}
